//
//  SNWritePresentationView.m
//  app
//
//  Created by 王少宁 on 15/5/13.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "SNWritePresentationView.h"

@interface SNWritePresentationView ()
@property (nonatomic, retain) UIView * backGroundView;
@property (nonatomic, strong) UIViewController * controller;
@end

@implementation SNWritePresentationView

+ (SNWritePresentationView *)shareView
{
    AS_SINGLETON(SNWritePresentationView, view, {
        view = [[SNWritePresentationView alloc] init];
    })
    return view;
}

- (void)viewWithController:(UIViewController *)controller string:(NSString *)string
{
    _controller = controller;
    controller.navigationController.navigationBar.hidden = YES;
    _backGroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, ScreenHeight)];
    _backGroundView.backgroundColor = [UIColor whiteColor];
    UITapGestureRecognizer*tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(viewClick)];
    [_backGroundView addGestureRecognizer:tapGesture];
    [controller.view addSubview:_backGroundView];
    
    CGFloat width = SCREEN_WIDTH-UF(48);
    CGFloat height = [XCommon heightForString:string fontSize:26 andWidth:width];
    CGFloat heightBasic = [XCommon heightForString:string fontSize:26 andWidth:1000000];
    UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(UF(24), (ScreenHeight-height)*0.5, width, height)];
    label.font = JKAppGlobleFontBigSymbol;
    label.text = string;
    if (height/heightBasic==1) {
        label.textAlignment = NSTextAlignmentCenter;
    } else {
        label.textAlignment = NSTextAlignmentLeft;
    }
    
    label.numberOfLines = 0;
    [_backGroundView addSubview:label];
}

- (void)viewClick
{
    _controller.navigationController.navigationBar.hidden = NO;
    [_backGroundView removeFromSuperview];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
